from django.db import models
from django.contrib.auth.models import AbstractUser

from yl_video.utils.base_model import BaseModel


class SexChoices(models.TextChoices):
    O = 'O', '女'
    I = 'I', '男'


# Create your models here.
# phone手机号 real_name真实名字 nationality 国籍 city 城市 user_icon FileFiled 头像 age sex  t_user
class UserModel(AbstractUser, BaseModel):
    phone = models.CharField(verbose_name='手机号', max_length=11, unique=True, blank=True, null=True)
    real_name = models.CharField(verbose_name='真实名字', blank=True, null=True, max_length=20)
    nationality = models.CharField(verbose_name='国籍', default='中国', blank=True, null=True, max_length=20)
    city = models.CharField(verbose_name='城市', blank=True, null=True, max_length=20)
    # 这里默认的是保存图片的路径
    user_icon = models.FileField(verbose_name="头像", max_length=200, null=True, blank=True, default='avatar.jpg')
    age = models.IntegerField(verbose_name='年龄', default=18, blank=True, null=True)
    sex = models.CharField(verbose_name="性别", choices=SexChoices.choices, default=SexChoices.O.value, max_length=10)

    class Meta:
        db_table = 't_user'
        verbose_name = '人员表'
        verbose_name_plural = verbose_name
        ordering = ['id']

    def __str__(self):
        return f'{self.id}, {self.username},{self.real_name}, {self.nationality}, {self.city}, {self.age},{self.sex},{self.user_icon}'


# 中间表 这个功能只要是关联对象，用户关联本来是一个对对多的模型对象，我们使用中间表把他变成一对多的
class CustomModel(BaseModel):
    itself_user = models.ForeignKey('UserModel', verbose_name='她自己', related_name='itself_list',
                                    on_delete=models.CASCADE)
    target_user = models.ForeignKey('UserModel', verbose_name='对方', related_name='target_list',
                                    on_delete=models.CASCADE)

    class Meta:
        db_table = 't_user_focus'
        verbose_name = '关注中间表'
        verbose_name_plural = verbose_name
        ordering = ['id']

    def __str__(self):
        return self.itself_user.username + self.target_user.username
